# 1.向函数传递参数
def greet(name):
    print(name)
greet('JarryLi')


# 2.关键字传参 -> 可以改变传递参数的位置
def describe_pet1(animal_type, pet_name):
    print(animal_type, pet_name)
describe_pet1(pet_name='dog', animal_type='<NAME>')


# 3.函数参数可以采用默认值的形式
def describe_pet2(animal_type, pet_name="name"):
    print(animal_type, pet_name)
describe_pet2(animal_type='dog')


# 4.返回值
def build_person(first_name, last_name):
    person = {first_name: last_name}
    return person
name = build_person('Jarry', 'Li')
print(name)


# 5.函数传递列表(这样传递会修改列表中的元素)
def greet_user(names):
    for name in names:
        print(name)
    names[2] = 'Carry'

usernames = ['Jarry', 'Li', 'Tom']
greet_user(usernames) # 传递的是实参本身
print(usernames)


# 6.禁止函数修改列表
def greet_user1(names):
    for name in names:
        print(name)
    names[2] = 'Carry'

usernames = ['Jarry', 'Li', 'Tom']
greet_user1(usernames[:]) # 这样传递的是实参的副本
print(usernames)


# 7.传递任意数量的实参
def make_pizza(*toppings):
    print(toppings)
make_pizza('a')
make_pizza('b', 'c', 'd')


# 8.使用任意数量的关键字实参
def build_profile(first, last, **userinfo):
    profile = {}
    profile['first_name'] = first
    profile['last_name'] = last
    for key, value in userinfo.items():
        profile[key] = value
    return profile

user_profile = build_profile('albert', 'einstein', location='princeton', field='physics')
print(user_profile)


# 9.导入外部函数
import Unit8_1 as pizza
# from Unit8_1 import make_pizza # 导入指定的模块
# from Unit8_1 import * # 导入模块中所有的函数
pizza.make_pizza(20, 'a', 'b', 'c')
